digit = input() 
if len(digit) == 4 and digit.isdigit(): 
    a = 0 
    for _ in range(4): 
        for i in range(_ + 1, 5): 
            number = int(digit[_:i]) 
            prostoe = True 
            if number <= 1: 
                prostoe = False 
            else: 
                for k in range(2, int(number**0.5) + 1): 
                    if number % k == 0: 
                        prostoe = False 
                        break 
            if prostoe and number > a: 
                a = number
    print(a)
    
else: 
    print(0)
